package ro.unibuc.nautilus.controllers.editors;

import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class DatePropertyEditor extends PropertyEditorSupport {

	private static SimpleDateFormat shortDateFormat = new SimpleDateFormat(
			"dd/MM/yyyy");

	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		try {
			setValue(shortDateFormat.parse(text));
		} catch (ParseException e) {
			throw new IllegalArgumentException(e);
		}
	}

	@Override
	public String getAsText() {
		if (getValue() == null) {
			return "";
		} else {
			return shortDateFormat.format(getValue());
		}
	}

}
